﻿<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;
        context.Response.ContentType = "text/html";
        var strResult = string.Empty;

        switch (context.Request.QueryString["RequestType"].Trim())
        {
            case "AddNum":
                strResult = this.AddNumber(
                        Convert.ToInt32(context.Request["number1"]), 
                        Convert.ToInt32(context.Request["number2"]));
                break;
        }
        context.Response.Write(strResult);
    }
    
    
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    public string AddNumber(int number1, int number2)
    {
        int total = 0;
        ClassLibrary1.Class1 sampleLib = new ClassLibrary1.Class1();
        total = sampleLib.AddNumber(number1, number2);
        var jsonData = new
          {
              Total = total
          };

        System.Web.Script.Serialization.JavaScriptSerializer javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        return javaScriptSerializer.Serialize(jsonData);
    }

}